using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;
// using UnityEngine.Rendering.Universal;

public class MaterialConverter : EditorWindow
{
    [MenuItem("Tools/Convert Materials to URP")]
    static void ConvertMaterials()
    {
        // 获取所有材质
        string[] materialGuids = AssetDatabase.FindAssets("t:Material");
        
        foreach (string guid in materialGuids)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            Material material = AssetDatabase.LoadAssetAtPath<Material>(path);
            
            if (material != null)
            {
                // 转换标准着色器到URP着色器
                if (material.shader.name == "Standard")
                {
                    material.shader = Shader.Find("Universal Render Pipeline/Lit");
                }
                else if (material.shader.name == "Standard (Specular setup)")
                {
                    material.shader = Shader.Find("Universal Render Pipeline/Lit");
                }
                else if (material.shader.name == "Legacy Shaders/Diffuse")
                {
                    material.shader = Shader.Find("Universal Render Pipeline/Lit");
                }
                else if (material.shader.name == "Legacy Shaders/Specular")
                {
                    material.shader = Shader.Find("Universal Render Pipeline/Lit");
                }
                else if (material.shader.name == "Legacy Shaders/Bumped Diffuse")
                {
                    material.shader = Shader.Find("Universal Render Pipeline/Lit");
                }
                else if (material.shader.name == "Legacy Shaders/Bumped Specular")
                {
                    material.shader = Shader.Find("Universal Render Pipeline/Lit");
                }
            }
        }
        
        AssetDatabase.SaveAssets();
        Debug.Log("材质转换完成！");
    }
}
